package com.yjzx.util.service.aop.ref.obj.event;

import com.yjzx.util.common.util.BeanUtils.BaseInterface;
import com.yjzx.util.service.aop.ref.obj.enums.OperateEnum;
import com.yjzx.util.service.enums.file.VideoFileTypeEnum;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;

import java.util.Collections;
import java.util.List;
import java.util.function.Function;

/**
 * @author guozhi
 * @date 2024/10/30
 * @description 缓存事件
 */
@Getter
public abstract class CacheEvent<V> extends ApplicationEvent {
    /**
     * 缓存的key
     */
    private Function<V, Object> function;
    /**
     * 操作的类型
     */
    private OperateEnum operate;
    /**
     * 需要操作的数据
     */
    private List<V> data;
    /**
     * 判断是否支持当前类型
     * @param cacheName 缓存名称
     * @return
     */
    public abstract boolean supports(String cacheName);
    public CacheEvent(Object source, V data, Function<V, Object> keyNameFunction, OperateEnum operate) {
        super(source);
        this.data = Collections.singletonList(data);
        this.function = keyNameFunction;
        this.operate = operate;
    }
    public CacheEvent(Object source, List<V> data, Function<V, Object> keyNameFunction, OperateEnum operate) {
        super(source);
        this.data = data;
        this.function = keyNameFunction;
        this.operate = operate;
    }

}
